package com.lzw.blog.admin.controller;

import com.lzw.blog.admin.service.PasswordResetService;
import com.lzw.blog.admin.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PasswordResetController {

    @Autowired
    private PasswordResetService passwordResetService;


    @PostMapping("/reset-password-request")
    public Result resetPasswordRequest(@RequestParam("email") String email) {
        return passwordResetService.sendPasswordResetLink(email);

    }


    @PostMapping("/reset-password")
    public Result resetPassword(@RequestBody ResetPasswordRequest resetPasswordRequest) {
        return passwordResetService.resetPassword(
                resetPasswordRequest.getToken(),
                resetPasswordRequest.getNewPassword(),
                resetPasswordRequest.getConfirmPassword()
        );
    }

    // 内部类，用于封装重置密码请求的数据
    public static class ResetPasswordRequest {
        private String token;
        private String newPassword;
        private String confirmPassword;

        // 省略 getter 和 setter 方法

        // 构造函数、getter、setter 等

        public String getToken() {
            return token;
        }

        public void setToken(String token) {
            this.token = token;
        }

        public String getNewPassword() {
            return newPassword;
        }

        public void setNewPassword(String newPassword) {
            this.newPassword = newPassword;
        }

        public String getConfirmPassword() {
            return confirmPassword;
        }

        public void setConfirmPassword(String confirmPassword) {
            this.confirmPassword = confirmPassword;
        }
    }
}
